<!DOCTYPE html>
<html>

<head>
    <title>提现</title>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1,user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="telephone=no" name="format-detection">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/flex.css">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/accounts-child.css">
    <script type="text/javascript" src="/resource/web/js/flexible.js"></script>
    <script type="text/javascript" src="/resource/web/js/jquery-1.11.1.min.js"></script>
</head>

<body>
    <div class="title">
        <p>提现</p>
        <a href="/Web/user_accounts" ><img class="back" src="/resource/web/img/newhead/path_7_copy.png"></a>
    </div>
    <div class="withdraw">
        @if(empty($tpldata['bankcard']))
            <script> alert("您还未实名认证");location='/Web/webauth_name.html';</script>
        @else
            <div class="wd-back">
                <p class="back-ico"><img src="{{$tpldata['bankcard']->bank_logo}}"></p>
                <p class="bk-name">{{$tpldata['bankcard']->bank_name}}</p>
                <p class="bk-num">尾号{{substr($tpldata['bankcard']->bank_num,-4)}}</p>
                <img class="dw-r" src="/resource/web/img/finacing/go_r3.png">
            </div>
        @endif
        <form action="/Web/cashing.html" target="_blank" id="submit_cash_form" method="post">
        <div class="wd-mon">
            <span id="money_format" money_format="{{$tpldata['fund']->money_format}}" money_unit="{{$tpldata['fund']->money_unit}}"></span>
            <p>提现金额<input type="number" id="input_amount" type="text" name="amount"  placeholder="可提金额：{{$tpldata['fund']->money_format}}元"></p>
        </div>
        <span class="rgm-er" id="error"></span>
        <div class="wd-mon">
            <p class="sxf">提现费用<span class="yue" id="amount_fee">0.00</span>元</p>
        </div>
            <a href="#0" id="submit_cash" ><div class="wd-btn">确定</div></a>
        </form>
        <p class="wdtishi">客服电话：&nbsp400-900-9017</p>
    </div>


    <script type="text/javascript" src="/resource/js/gpw/main.js"></script>
    <script>

        var accountUrl  = "{url('/user/account/index?is_idcard=1')}";
        var cashUrl     = "{url('/user/cash/withdraw')}";
        var fundUrl     = "{url('/user/fund/index')}";
        //var money       = {$fund.money_unit};
        //var money_format= "{$fund.money_format}";
        var cashFeeUrl  = "{url('/user/cash/get_cash_fee')}";


        var is_request  = false;
        var inputAmount = $('#input_amount');
        // 手续费相关对象
        //var amountPlan  = $('#amount_plan');
        var money       = $('#money_format').attr('money_unit');
        var money_format= $('#money_format').attr('money_format');
        var amountFee   = $('#amount_fee');
        //var amountFeeDetail = $('#amount_fee_detail');
        var depositFeeTpl   = '充值未投资提现手续费：';
        var liveFeeTpl      = '回款及福利提现手续费：';

        // 回车键操作
        $(document).keydown(function(event){
            if(event.keyCode ==13)
            {
                $('#submit_cash').click();
                return false;
            }
        });

        //    $('.tipicon').mouseover(function(){
        //        var info = $(this).attr('info');
        //        var index = layer.tips(info, $(this),{
        //            tips : [1, '#3595CC'],
        //            time : 100000,
        //            area : ['', ''],
        //            maxWidth : '500px',
        //        });
        //    });

        //    $('.tipicon').mouseleave(function(){
        //        layer.closeAll('tips');
        //    });


        function cashFee()
        {
            var amount = inputAmount.val()*100;
            if (amount <= 0 || amount > money*100)
            {
                alert("金额不正确");return;
                //$("#error").html("金额不正确");return ;
            }else{
                $("#error").html('');
            }

            $.ajax({
                url      : '/Web/cashfee.html',
                type     : 'post',
                data     : 'amount='+amount,
                async    : false,
                timeout  : 25,
                error : function (xmlHttpRequest, error) {
                    var errorMsg = (error == 'timeout') ? '网络可能不给力哦，请重试...' : '服务器繁忙，请稍候再试';
                    alert(errorMsg);
                },
                success : function (redata)
                {
                    if (redata.code == 200)
                    {
                        $("#error").html('');
                        amountFee.html(redata.data.totalFee_unit)
                    }
                    else
                    {
                        alert(redata);
                        return;
                        //$("#error").html(redata);
                    }
                }
            });

//        $.getJSON(cashFeeUrl, {amount:amount}, function(redata){
//            if (redata.status == 200)
//            {
//               // amountPlan.html(redata.data.amountPlan_unit);
//                amountFee.html(redata.data.totalFee_unit);
//                var feeTpl = depositFeeTpl+redata.data.depositFee_unit+' 元<br>'+liveFeeTpl+redata.data.liveFee_unit+' 元';
//                amountFeeDetail.attr('info', feeTpl);
//            }
//            else
//            {
//                amountPlan.html(0);
//                amountFee.html(0);
//                var feeTpl = depositFeeTpl+'0 元<br>'+liveFeeTpl+'0 元';
//                amountFeeDetail.attr('info', feeTpl);
//            }
//        });
        }

        var setTime = null;

        // 计算提现手续费


      var status = inputAmount.keyup(function(){
            //clearTimeout(setTime);
            cashFee();
        });



        // 提交
        $('#submit_cash').click(function(){
            var amount = $.trim(inputAmount.val());

            if (is_request)
            {
                return;
            }

            if (amount == '' || amount == null)
            {
                alert("金额不正确");
                //$("#error").html("金额不能为空")
                return ;
            }else{
                $("#error").html('');
            }

            if (isNaN(amount))
            {
                alert("请输入充值金额, 充值金额只能是纯数字");
                //$("#error").html("请输入充值金额, 充值金额只能是纯数字");
                return;
            }else{
                $("#error").html('');
            }

            if (money*100 < amount*100)
            {
                alert('您输入的提现金额不能大于可用余额，当前可用余额为：'+money_format+' 元');
               // $("#error").html('您输入的提现金额不能大于可用余额，当前可用余额为：'+money_format+' 元');
                return;
            }else{
                $("#error").html('');
            }


            is_request = true;

            $.ajax({
                url      : '/Web/cashing.html',
                type     : 'post',
                data     : 'amount='+amount,
                async    : false,
                dataType : 'json',
                timeout  : 25,
                error : function (xmlHttpRequest, error) {
                    var errorMsg = (error == 'timeout') ? '网络可能不给力哦，请重试...' : '服务器繁忙，请稍候再试';
                    alert(errorMsg)
                    is_request = false;
                },
                success : function (redata)
                {
                    if (redata.status == 200)
                    {
                        $('#submit_cash_form').submit();
                    }
                    else{
                        alert(redata.msg);
                        //$("#error").html(redata.msg);
                        return;
                    }
                    is_request = false;
                }
            });
        });

        //    if (is_idcard == 0)
        //    {
        //        layer.alert('为保证您的账户与资金安全，需要您完成身份认证', {
        //            btn  : ['确认'],
        //            icon : 0,
        //            title: '身份认证',
        //            closeBtn : 0,
        //        }, function(){
        //            location.href=accountUrl;
        //        });
        //    }
        //    else if (is_bankcard == 0)
        //    {
        //        layer.alert('您还未绑定银行卡，无法进行提现', {
        //            btn  : ['立即绑定'],
        //            icon : 0,
        //            title: '绑定银行卡',
        //            closeBtn : 0,
        //        }, function(){
        //            location.href=accountUrl;
        //        });
        //    }


        var read = false;
        $('.read_img').click(function(){
            if(read){
                $(this).attr('src','_RESOURCE/images/user/txt_click.png');
                read = false;
            }else{
                $(this).attr('src','_RESOURCE/images/user/txt_no.png');
                read = true;
            }
        });
    </script>
</body>

</html>
